<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>奖励</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>奖励{{detail.id?'修改':'添加'}}</legend>
        </fieldset>

        <form class="layui-form" action="javascript:;" lay-filter="this-form">
            <input type="hidden" name="id" :value="detail.id">

            <div class="layui-form-item">
                <label class="layui-form-label">邮件标题:</label>
                <div class="layui-input-block">
                    <input type="text" name="title" :value="detail.title" autocomplete="off" placeholder="请输入邮件标题" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮件正文:</label>
                <div class="layui-input-block">
                    <input type="text" name="content" :value="detail.content" autocomplete="off" placeholder="请输入邮件正文" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务器ID:</label>
                <div class="layui-input-block">
                    <input type="number" step="1" name="server_id" :value="detail.server_id" autocomplete="off" placeholder="请输入服务器ID" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">网站账号ID:</label>
                <div class="layui-input-block">
                    <input type="number" step="1" name="customer_id" :value="detail.customer_id" autocomplete="off" placeholder="请输入网站账号ID" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">元宝:</label>
                <div class="layui-input-block">
                    <input type="number" step="1" name="yuanbao" :value="detail.yuanbao" autocomplete="off" placeholder="请输入元宝" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">华夏币:</label>
                <div class="layui-input-block">
                    <input type="number" step="1" name="hxb" :value="detail.hxb" autocomplete="off" placeholder="请输入华夏币" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">银元:</label>
                <div class="layui-input-block">
                    <input type="number" step="1" name="yinyuan" :value="detail.yinyuan" autocomplete="off" placeholder="请输入银元" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">奖励道具:</label>
                <div class="layui-input-block">
                        <textarea name="equips" class="layui-textarea" id="textarea-equips" placeholder="请输入奖励道具">{{detail.equips}}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间:</label>
                <div class="layui-input-block">
                        <input type="text" name="begin_time" :value="detail.begin_time" autocomplete="off" class="layui-input" id="datetime-begin_time">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间:</label>
                <div class="layui-input-block">
                        <input type="text" name="end_time" :value="detail.end_time" autocomplete="off" class="layui-input" id="datetime-end_time">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间:</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="0" title="未领取"
                           :checked="(!detail.id && true) || (detail.id && detail.status === 0 ) ? true: false"
                    >
                    <input type="radio" name="status" value="1" title="已领取"
                           :checked="(!detail.id && false) || (detail.id && detail.status === 1 ) ? true: false"
                    >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">序号:</label>
                <div class="layui-input-block">
                    <input type="number" step="1" name="sort" :value="detail.sort" autocomplete="off" placeholder="请输入序号" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    var Id = urlParam('id')
    var form = null;
    var laydate = null;
    var _this=null;
    var $ = null;
    var layer = null;
    new Vue({
        el:"#app",
        data:{
            detail:{ // Vue 赋值, layui取值
                id:Id,
                title:null,
                content:null,
                server_id:null,
                name:null,
                customer_id:null,
                yuanbao:null,
                hxb:null,
                yinyuan:null,
                equips:null,
                begin_time:null,
                end_time:null,
                status:null,
                sort:null,
            }
        },
        methods:{

        },
        created:function(){
            _this = this;
            layui.use(['form','laydate'],function(){
                $ = layui.$;
                form = layui.form;
                laydate = layui.laydate;
                layer = layui.layer;
            })
        },
        updated:function(){
            form.render();
        },
        mounted:function(){
            layui.use(['form'], function () {
                //初始化
            laydate.render({
                elem:"#datetime-begin_time",
                value: "",
                type: 'datetime'
            });
            laydate.render({
                elem:"#datetime-end_time",
                value: "",
                type: 'datetime'
            });
            if (Id){ //编辑操作
                $.get("/admin/rewards/"+Id,{},function(res){ //获取数据
                    _this.detail = res.data
                    if (res.code===0){
                        _this.detail = res.data;
                        form.val('this-form',res.data)
                    }
                });
            }
            //监听提交
            form.on('submit(submit)', function (data) {
                var formData = data.field;
                if (Id){ //update
                    formData._method = 'put';
                    $.post("/admin/rewards/"+Id,formData,function(res){
                        if (res.code===0){
                            layer.msg('success',{icon:6,time:500},function(){
                                parent.location.reload();//父页面刷新
                            })
                        } else {
                            layer.msg(res.msg,{icon:5})
                        }
                    })
                } else { //add
                    $.post("/admin/rewards/insert",formData,function(res){
                        if (res.code===0){
                            layer.msg('success',{icon:6,time:500},function(){
                                parent.location.reload(); //父页面刷新
                            })
                        } else {
                            layer.msg(res.msg,{icon:5})
                        }
                    })
                }
                return false;
            });
        });
    }
    })
</script>
</body>
</html>
